/*
 * Project Name: cms_web
 * File Name: SinglePageListTag.java
 * Copyright: ZKTeco Corporation 2015
 * Description: TODO 请在此处添加对本文件的描述
 * Creator: Administrator
 * Create Date: 2015年3月23日 下午4:32:05
 */
package com.shishuo.cms.tag;

import static freemarker.template.ObjectWrapper.BEANS_WRAPPER;

import java.io.IOException;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shishuo.cms.entity.ClassesEntity;
import com.shishuo.cms.entity.DownPageEntity;
import com.shishuo.cms.entity.SinglePageEntity;
import com.shishuo.cms.entity.vo.PageVo;
import com.shishuo.cms.plugin.TagPlugin;
import com.shishuo.cms.service.ClassesService;
import com.shishuo.cms.service.SinglePageService;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

@Service
public class SinglePageListTag extends BaseTagPlugin
{
	@Override
	public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException
	{
		String aliasName = params.get("aliasName").toString();
		int page = Integer.parseInt(params.get("p").toString());
		try {
			ClassesEntity classesEntity=classesService.getByAliasName(aliasName);
			if (null!=classesEntity) {
				PageVo<SinglePageEntity>  pageList=singlePageService.getAllListPageByClassId(page,classesEntity.getId());
				env.setVariable("tag_single_list", BEANS_WRAPPER.wrap(pageList));
			}
			env.setVariable("tag_class", BEANS_WRAPPER.wrap(classesEntity));
			body.render(env.getOut());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
